package cn.itcast.tlias.com.tliaswork.controller;
import cn.itcast.tlias.com.tliaswork.pojo.Result;
import cn.itcast.tlias.com.tliaswork.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
public class UpLoadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;
    //本地上传
//    @PostMapping("/upload")
//    public Result upLoad(String name, Integer age, MultipartFile image) throws Exception{
//        log.info("收到的数据是{}:{}:{}",name,age,image);
//        String uuid = UUID.randomUUID().toString();
//        image.transferTo(new File("D:\\down\\nana\\"+uuid+image.getOriginalFilename()));
//        return Result.success();
//    }
    @PostMapping("/upload")
    public Result upLoad(String name, Integer age, MultipartFile image) throws Exception{
        // Endpoint以华东1（杭州）为例，其它Region请按实际情况填写。
        String file = aliOSSUtils.uploadFile(image);

        return Result.success(file);
    }
}
